/**
 *******************************************************************************
 * @FileName  : tlsr825x_irq.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-09-10
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */
#ifndef TLSR825X_IRQ_H_
#define TLSR825X_IRQ_H_

#include "tlsr825x.h"

/*!   Peripheral Interrupt Mask define */
#define IRQ_TIM0            ((uint32_t)0x00000001) /*!< Need clear own IRQ flag manually. not need clear IRQ source manually. */
#define IRQ_TIM1            ((uint32_t)0x00000002)
#define IRQ_TIM2            ((uint32_t)0x00000004)
#define IRQ_USB_PWR_DN      ((uint32_t)0x00000008)
#define IRQ_DMA             ((uint32_t)0x00000010)
#define IRQ_DFIFO           ((uint32_t)0x00000020)
#define IRQ_UART            ((uint32_t)0x00000040)
#define IRQ_IIC             ((uint32_t)0x00000080)
#define IRQ_SPI             ((uint32_t)0x00000080)
#define IRQ_USB_EDP0_SETUP  ((uint32_t)0x00000100)
#define IRQ_USB_EDP0_DATA   ((uint32_t)0x00000200)
#define IRQ_USB_EDP0_STA    ((uint32_t)0x00000400)
#define IRQ_USB_SET_INTF    ((uint32_t)0x00000800)
#define IRQ_USB_EDP_DATA    ((uint32_t)0x00001000)
#define IRQ_RF              ((uint32_t)0x00002000)
#define IRQ_PWM             ((uint32_t)0x00004000)
#define IRQ_rcv             ((uint32_t)0x00008000)
#define IRQ_USB_250US       ((uint32_t)0x00010000) /*!< Need clear IRQ Source manually.*/
#define IRQ_USB_RST         ((uint32_t)0x00020000) /*!< Need clear IRQ Source manually.*/
#define IRQ_GPIO            ((uint32_t)0x00040000) /*!< Need clear IRQ Source manually.*/
#define IRQ_PM              ((uint32_t)0x00080000) /*!< Need clear IRQ Source manually.*/
#define IRQ_SYS_TIM         ((uint32_t)0x00100000) /*!< Need clear IRQ Source manually.*/
#define IRQ_GPIO_RSIC0      ((uint32_t)0x00200000) /*!< Need clear IRQ Source manually.*/
#define IRQ_GPIO_RSIC1      ((uint32_t)0x00400000) /*!< Need clear IRQ Source manually.*/

#define IRQ_ALL             ((uint32_t)0x00FFFFFF)


/**
 * @brief : Enable Global IRQ.
 * @param : none.
 * @param : none.
 */
static inline void IRQ_Enable(void)
{
	REG_8(0x643) = 0x01;
}

/**
 * @brief : Disable Global IRQ.
 * @param : none.
 * @param : none.
 */
static inline void IRQ_Disable(void)
{
	REG_8(0x643) = 0x00;
}

/**
 * @brief : Enable specified peripheral IRQ.
 * @param : IRQx      can be  IRQ_TIM0/IRQ_TIM1 ...
 * @param : none.
 */
static inline void IRQ_EnablePeriphIrq(uint32_t IRQx)
{
	IRQ->IRQ_MASK |= IRQx;
}

/**
 * @brief : Disable specified peripheral IRQ.
 * @param : IRQx       can be  IRQ_TIM0/IRQ_TIM1...
 * @param : none.
 */
static inline void IRQ_DisablePeriphIrq(uint32_t IRQx)
{
	IRQ->IRQ_MASK &= ~IRQx;
}

/**
 * @brief : Get IRQ state.
 * @param : IRQx       can be IRQ_TIM0/IRQ_TIM1 ...
 *
 * @param : none.
 */
static inline uint8_t IRQ_GetIrqState(uint32_t IRQx)
{
	return (IRQ->IRQ_SRC & IRQx) ? 1:0;
}

/**
 * @brief : Clean edged-trigger IRQ state.
 * @param : IRQx      only can be IRQ_USB_250/IRQ_USB_RST/IRQ_GPIO/IRQ_PM/IRQ_SYS_TIM/
 *                                IRQ_GPIO_RSIC0/IRQ_GPIO_RSIC1
 * @param : none.
 */
static inline void IRQ_CleanIrqState(uint32_t IRQx)
{
	IRQ->IRQ_SRC = IRQx;//Write 1 clean.
}

#endif /* TLSR825X_IRQ_H_ */
